<a href='http://github.com/angular/angular.js/edit/master/src/ng/filter.js' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this doc</a>



<a href='http://github.com/angular/angular.js/tree/master/src/ng/filter.js#L3' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">$filterProvider</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
  <li>
    <a href="api/ng/service/$filter">- $filter</a>
  </li>

    <li>
      - provider in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>Filters are just functions which transform input to an output. However filters need to be
Dependency Injected. To achieve this a filter definition consists of a factory function which is
annotated with dependencies and is responsible for creating a filter function.</p>
<pre><code class="lang-js">  // Filter registration
  function MyModule($provide, $filterProvider) {
    // create a service to demonstrate injection (not always needed)
    $provide.value(&#39;greet&#39;, function(name){
      return &#39;Hello &#39; + name + &#39;!&#39;;
    });

    // register a filter factory which uses the
    // greet service to demonstrate DI.
    $filterProvider.register(&#39;greet&#39;, function(greet){
      // return the filter function which uses the greet service
      // to generate salutation
      return function(text) {
        // filters need to be forgiving so check input validity
        return text &amp;&amp; greet(text) || text;
      };
    });
  }</code></pre>
<p>The filter function is registered with the <code>$injector</code> under the filter name suffix with
<code>Filter</code>.</p>
<pre><code class="lang-js">  it(&#39;should be the same instance&#39;, inject(
    function($filterProvider) {
      $filterProvider.register(&#39;reverse&#39;, function(){
        return ...;
      });
    },
    function($filter, reverseFilter) {
      expect($filter(&#39;reverse&#39;)).toBe(reverseFilter);
    });</code></pre>
<p>For more information about how angular filters work, and how to create your own filters, see
<a href="guide/filter">Filters</a> in the Angular Developer Guide.</p>

</div>




<div>
  

    

  

  
<h2>Methods</h2>
<ul class="methods">
  <li id="register">
    <h3><p><code>register(name, fn);</code></p>

</h3>
    <div><p>Register filter factory function.</p>
</div>

    
    <h4>Parameters</h4>
    
<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        name
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-string">String</a>
      </td>
      <td>
        <p>Name of the filter.</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        fn
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-function">Function</a>
      </td>
      <td>
        <p>The filter factory function which is injectable.</p>

        
      </td>
    </tr>
    
  </tbody>
</table>

    

    
    
    

  </li>
  </ul>
  
  



  
</div>


